package com.java110.mall.shop.smo.impl;


import com.java110.mall.shop.dao.ICouponConfServiceDao;
import com.java110.intf.shop.ICouponConfInnerServiceSMO;
import com.java110.dto.coupon.CouponConfDto;
import com.java110.po.coupon.CouponConfPo;
import com.java110.utils.util.BeanConvertUtil;
import com.java110.core.base.smo.BaseServiceSMO;
import com.java110.dto.PageDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName FloorInnerServiceSMOImpl
 * @Description 会员优惠券设置内部服务实现类
 * @Author wuxw
 * @Date 2019/4/24 9:20
 * @Version 1.0
 * add by wuxw 2019/4/24
 **/
@RestController
public class CouponConfInnerServiceSMOImpl extends BaseServiceSMO implements ICouponConfInnerServiceSMO {

    @Autowired
    private ICouponConfServiceDao couponConfServiceDaoImpl;


    @Override
    public int saveCouponConf(@RequestBody  CouponConfPo couponConfPo) {
        int saveFlag = 1;
        couponConfServiceDaoImpl.saveCouponConfInfo(BeanConvertUtil.beanCovertMap(couponConfPo));
        return saveFlag;
    }

     @Override
    public int updateCouponConf(@RequestBody  CouponConfPo couponConfPo) {
        int saveFlag = 1;
         couponConfServiceDaoImpl.updateCouponConfInfo(BeanConvertUtil.beanCovertMap(couponConfPo));
        return saveFlag;
    }

     @Override
    public int deleteCouponConf(@RequestBody  CouponConfPo couponConfPo) {
        int saveFlag = 1;
        couponConfPo.setStatusCd("1");
        couponConfServiceDaoImpl.updateCouponConfInfo(BeanConvertUtil.beanCovertMap(couponConfPo));
        return saveFlag;
    }

    @Override
    public List<CouponConfDto> queryCouponConfs(@RequestBody  CouponConfDto couponConfDto) {

        //校验是否传了 分页信息

        int page = couponConfDto.getPage();

        if (page != PageDto.DEFAULT_PAGE) {
            couponConfDto.setPage((page - 1) * couponConfDto.getRow());
        }

        List<CouponConfDto> couponConfs = BeanConvertUtil.covertBeanList(couponConfServiceDaoImpl.getCouponConfInfo(BeanConvertUtil.beanCovertMap(couponConfDto)), CouponConfDto.class);

        return couponConfs;
    }


    @Override
    public int queryCouponConfsCount(@RequestBody CouponConfDto couponConfDto) {
        return couponConfServiceDaoImpl.queryCouponConfsCount(BeanConvertUtil.beanCovertMap(couponConfDto));    }

    public ICouponConfServiceDao getCouponConfServiceDaoImpl() {
        return couponConfServiceDaoImpl;
    }

    public void setCouponConfServiceDaoImpl(ICouponConfServiceDao couponConfServiceDaoImpl) {
        this.couponConfServiceDaoImpl = couponConfServiceDaoImpl;
    }
}
